package org.hk.proxy.server.channel;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.FullHttpRequest;
import org.hk.proxy.server.web.ApiRouteResolve;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HttpRequestHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
    private static final Logger log = LoggerFactory.getLogger(HttpRequestHandler.class);
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg){
        ApiRouteResolve.writeAndFlush(ctx,msg);
    }
    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        log.info("htt request inactive...");
        super.channelInactive(ctx);
    }
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        log.info("http request active..");
        super.channelActive(ctx);
    }
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        log.error("异常:",cause);
        ctx.channel().close();
        super.exceptionCaught(ctx, cause);
    }
}
